{% extends "admin/base_site.html" %}
{% load i18n %}

{% block extrahead %}{{block.super}}{% if not 'navbar' in request.session or request.session.navbar %}
<script>
$(function() {
  breadcrumbs_reflow();
  $(window).resize(breadcrumbs_reflow);

  $(".selectdb li a").click(selectDatabase);

  $("#nav-menu li.dropdown").mouseenter(
      function() { if ( !$(this).hasClass("open") && window.innerWidth >= 768) $('.dropdown-toggle', this).dropdown('toggle');}
  );
  $("#nav-menu li.dropdown").mouseleave(
      function() { if ($(this).hasClass("open") && window.innerWidth >= 768) $('.dropdown-toggle', this).dropdown('toggle');}
  );
});

</script>
{% endif %}{% endblock %}

{% block nav-global %}{% if not 'navbar' in request.session or request.session.navbar %}
{% getMenu as menu %}
<nav id="nav-menu-header" class="navbar navbar-static-top navbar-default">
	<div class="container-fluid">
	  <div class="navbar-header">
	      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#nav-menu" aria-expanded="false">
	        <span class="sr-only">Toggle navigation</span>
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
	        <span class="icon-bar"></span>
	      </button>

          {% if not request.session.navbar %}
	      <a class="navbar-brand" style="padding-top:5px; padding-bottom: 5px">
          {% block branding %}{{ block.super }}{% endblock %}
          </a>
          {% endif %}
	  </div>

		<div id="nav-menu" class="collapse navbar-collapse">
			<ul class="nav navbar-nav">
			  {% for group in menu %}{% if group.2 %}
			  <li class="dropdown">
			    <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{{ group.0 }}</a>
			    <ul class="dropdown-menu">
			      {% for item in group.1 %}
			        {% if item.4 %}
			        {% if item.1.separator %}<li role="separator" class="divider"></li>
			        {% else %}<li><a {% if item.1.identifier %}id="{{item.1.identifier}}" {% endif %}{% if item.1.window %}target="_blank" rel="noopener" {% endif %}{% if item.1.javascript %}href="javascript:void(0);" onclick="{{ item.1.javascript }}; return false;"{% else %}href="{% if item.1.prefix %}{{request.prefix}}{% endif %}{{ item.1.url }}"{% endif %} data-populated="{{ item.3 }}">{{ item.0 }}</a></li>
			        {% endif %}
			        {% endif %}
			      {% endfor %}
			    </ul>
			  </li>{% endif %}
			  {% endfor %}
			</ul>

			<form class="navbar-form navbar-left" role="search">
				<div class="form-group">
				  <input id="search" class="form-control typeahead" type="text" placeholder="&#xf002; {% trans 'Search' %}">
				</div>
			</form>

          {% if not request.session.navbar and user.is_authenticated and user.is_staff %}<ul class="nav navbar-nav navbar-right">
		    <li class="dropdown">
		    <a href="#" class="dropdown-toggle" style="
    padding-right: 20px;" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans 'user'|capfirst %} {% firstof user.first_name user.username %}</a>
				<ul class="dropdown-menu">
				  <li><a href="{{request.prefix}}/preferences/">{% trans 'preferences'|capfirst %}</a></li>
				  <li><a href="/data/logout/?next=/">{% trans 'Log out'|capfirst %}</a></li>
				</ul>
			  </li></ul>
          {% endif %}
		</div>

	  <div class="row breadcrumbrow">
		  <div class="col-sm-10">
		     <ol class="breadcrumb" id="breadcrumbs">
		       <li><a id="cockpitcrumb" href="{{request.prefix}}/">{% trans 'cockpit'|capfirst %}</a></li>
		       {% crumbs %}
		     </ol>
		  </div>

			<div class="col-sm-2 pull-right">
			  <div class="selectdb ">
				{% if user.scenarios|length > 1 %}
					<button class="form-control btn btn-default dropdown-toggle" type="button" id="database"
					   data-original-title="{% trans "Choose a what-if scenario" %}" data-placement="left"
                       data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" name="{{ request.scenario.name }}">
					{{ request.scenario.description }}&nbsp;<span class="caret"></span>
					</button>
					<ul class="dropdown-menu" aria-labelledby="database">
					{% for sc in user.scenarios|sortList %}<li>
					  <a data-database="{{ sc.name }}">{{ sc.description }}
					  {% if sc.help_url %}
					  <span onclick="window.open('{{sc.help_url|safe}}'); event.stopPropagation()" style="float:right" class="fa fa-question-circle"></span>
					  {% endif %}</a>
					  </li>{% endfor %}
					</ul>
				{% endif %}
				</div>
			</div>
	  </div>
  </div> <!--  end of container -->
</nav>

{% endif %}{% endblock %}